﻿<%@ Page Language="C#" Title="模型页面" MasterPageFile="~/W_View/PageMaster.Master" CodeBehind="Dm_ModelgroupPage.aspx.cs" Inherits="STHPMS1.Web.W_View.Decision.Dm_ModelgroupPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">    
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Enum.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/JsPage.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Appearance.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Bussiness.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/Highcharts/highcharts.js")%> 

    <script type="text/javascript">      

		var _view = new JsPage();
        var _css = new Appearance();

        function onShowClick() {
            var row = $('#dg').datagrid('getSelected');

            if (!row) {
                $.messager.alert('消息提示', '请选择一个模型!', 'warning');
                return;
            }

            $.messager.progress({
                title: '请等待',
                msg: '加载数据中...'
            });

            $.ajax({
                type: 'get',
                async: false,
                url: '/api/modelgroup/show?modelId=' + row.MODELGROUP_ID,
                cache: false,
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (data) {
                    $("#fm").form('load', data);
                    if (row.LASTYEAR == row.PERFYEAR) {
                        $("#btnSave").hide();
                    } else {
                        $("#btnSave").show();
                    }                    
                    $("#dlg").dialog('open');
                },
                error: Common.ShowError
            });
        }
        function onCloseClick() {
            _view.closeDialog();
        }

        function onSumbitClick() {
            var count = $('#PciCount').numberbox('getValue');
            if (!count || count < 2)
            {
                $.messager.alert('消息提示', '必须要有两个以上数据点才可以进行模型校正!', 'warning');
                return;
            }

            var modelname = $('#ModelName').numberbox('getValue');
            var beginyear = $('#BeginYear').numberbox('getValue');
            var endyear = $('#EndYear').numberbox('getValue');

            var data = [];
            for (var i = beginyear; i <= endyear; i++) {
                data.push({ id: i, text: i });
            }
            
            $('#ModelName1').textbox('setValue', modelname);
            $('#cmbBeginYear').combobox('loadData', data).combobox('clear');
            $('#cmbEndYear').combobox('loadData', data).combobox('clear');

            $('#cmbBeginYear').combobox('setValue', data[0].id)
            $('#cmbEndYear').combobox('setValue', data[data.length - 1].id)

            $("#dlg1").dialog('open');
            $("#dlg").dialog('close');
        }

        function onAdjustClick() {
            var row = $('#dg').datagrid('getSelected');
            var modelId = row.MODELGROUP_ID;
            var modelMode = $('#cmbModelMode').combobox('getValue');
            var beginYear = $('#cmbBeginYear').combobox('getValue');
            var endYear = $('#cmbEndYear').combobox('getValue');

            $.messager.progress({
                title: '请等待',
                msg: '加载数据中...'
            });

            $.ajax({
                type: 'get',
                async: false,
                url: '/api/modelgroup/calc?modelId=' + modelId + '&modelMode=' + modelMode + '&beginYear=' + beginYear + '&endYear=' + endYear,
                cache: false,
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (data) {
                    $("#fm").form('load', data);
                    if (row.LASTYEAR == row.PERFYEAR) {
                        $("#btnSave").hide();
                    } else {
                        $("#btnSave").show();
                    }
                    $("#dlg1").dialog('close');
                    onGraphicClick();
                },
                error: Common.ShowError
            });
        }

        function onGraphicClick() {
            var row = $('#dg').datagrid('getSelected');

            if (!row) {
                $.messager.alert('消息提示', '请选择一个模型!', 'warning');
                return;
            }

            $.messager.progress({
                title: '请等待',
                msg: '加载数据中...'
            });

            $.ajax({
                type: 'get',
                async: false,
                url: '/api/modelgroup/graphic?modelId=' + row.MODELGROUP_ID,
                cache: false,
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (data) {
                    if (data) {
                        $('#container').highcharts(data);
                        $("#dlg2").dialog('open');
                    }
                },
                error: function (err) {
                    $.messager.alert('错误提示', err.responseJSON.ExceptionMessage, 'error');
                }
            });
        }

        $(function () {           
            
            $("#btnShow").on("click", onShowClick);
            $("#btnSave").on("click",onSumbitClick );
            $("#btnCancel").on("click", onCloseClick);
            $("#btnAdjust").on("click", onAdjustClick);
            $("#btnGraph").on("click", onGraphicClick);
            
            _view.setForm($('#fm'))
                .setDialog($('#dlg'))
                .setDataGrid($('#dg'))
                .loadDataGrid("/api/modelgroup");


            $("#cmbIndex").combobox({ onChange: onSearchClick });
            $("#cmbPvmt").combobox({ onChange: onSearchClick });
            $("#cmbBasic").combobox({ onChange: onSearchClick });
            $("#cmbModel").combobox({ onChange: onSearchClick });
            $("#cmbType").combobox({ onChange: onSearchClick });
            $("#chkCheck").change(onSearchClick);
            
            combobox_loadData();
        });

        function onSearchClick(n, o) {
            var index = $('#cmbIndex').combobox("getValue");
            var pvmt = $('#cmbPvmt').combobox("getValue");
            var basic = $('#cmbBasic').combobox("getValue");
            var model = $('#cmbModel').combobox("getValue");
            var type = $('#cmbType').combobox("getValue");
            var check = $('#chkCheck').is(':checked');
         
            var data = [];
            data.push({ key: "index", value: index });
            data.push({ key: "pvmt", value: pvmt });
            data.push({ key: "basic", value: basic });
            data.push({ key: "model", value: model });
            data.push({ key: "type", value: type });
            data.push({ key: "check", value: check });

            _view.SearchAction(data);
        }

        function combobox_loadData()
        {
            var dataIndex = EnumEx.getDicts(RegressionIndicatorsEnum, function (id) {
                if (id == RegressionIndicatorsEnum.PCI802)
                    return true;
                else
                    return false;
            });
            if (dataIndex)
                $('#cmbIndex').combobox('loadData', dataIndex).combobox('clear');

            var dataPvmt = EnumEx.getDicts(PavementTypeEnum, function (id) {
                if (id == PavementTypeEnum.P21)
                    return true;
                else
                    return false;
            });
            if (dataPvmt)
                $('#cmbPvmt').combobox('loadData', dataPvmt).combobox('clear');

            var dataBasic = EnumEx.getDicts(RoadBasicTypeEnum, function (id) {
                if (id == RoadBasicTypeEnum.B165 || id == RoadBasicTypeEnum.B166 || id == RoadBasicTypeEnum.B167)
                    return true;
                else
                    return false;
            });
            if (dataBasic)
                $('#cmbBasic').combobox('loadData', dataBasic).combobox('clear');

            var dataModel = EnumEx.getDicts(ModelFormEnum, function (id) {
                if (id == ModelFormEnum.M821)
                    return true;
                else
                    return false;
            });
            if (dataModel)
            {   
                $('#cmbModel').combobox('loadData', dataModel).combobox('clear');
                $('#cmbModelMode').combobox('loadData', dataModel).combobox('clear');
                $('#cmbModelMode').combobox('setValue', dataModel[0].id)
            }
            
            var dataType = EnumEx.getDicts(MainTypeEnum, function (id) {
                if (id == MainTypeEnum.M12000)
                    return false;
                else
                    return true;
            });
            if (dataType)
                $('#cmbType').combobox('loadData', dataType).combobox('clear');

            
        }
        
    </script>    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table id="dg"  class="easyui-datagrid content-place"  data-ajaxcached="false"  data-options='{
                  "title": "模型数据",
                  "toolbar": "#tb",
                  "method": "get",
                  "iconCls": "icon-edit",
                  "width": "auto",
                  "height": "auto",
                  "nowrap": false,
                  "striped": true,
                  "border": true,
                  "collapsible": false,
                  "fit": false,
                  "singleSelect": true,
                  "rownumbers": true,
                  "pagination": true,
                  "rowStyler":function(index,row){                                
                        if (row.LASTYEAR!=row.PERFYEAR){    
                            return "color:red;font-weight:bold;";    
                        }    
                    }  
                }' >
        <thead>
			<tr>
				<th data-options="field:'MODELGROUP_ID',editor:'text',width:80,align:'center' ,hidden:true">模型组ID</th>
                <th data-options="field:'INDEXTYPE_DICTID',editor:'numberbox',width:80,align:'center',formatter:formatEnum ">指标类型</th>
                <th data-options="field:'PVMTTYPE_DICTID',editor:'numberbox',width:80,align:'center' ,formatter:formatEnum">面层类型</th>
                <th data-options="field:'BASICTYPE_DICTID',editor:'numberbox',width:80,align:'center',formatter:formatEnum ">路面类型</th>
                <th data-options="field:'MODELMODE_DICTID',editor:'numberbox',width:80,align:'center' ,formatter:formatEnum">模型形式</th>
                <th data-options="field:'MODELTYPE_DICTID',editor:'numberbox',width:100,align:'center' ,formatter:formatEnum">实施过的养护类型</th>
                <th data-options="field:'COMMENT',editor:'text',width:80,align:'center' ">预养护措施</th>			
                <th data-options="field:'THICK_MIN',editor:'numberbox',width:100,align:'center',min:0,precision:2  ">面层厚度最小值</th>
                <th data-options="field:'THICK_MAX',editor:'numberbox',width:100,align:'center',min:0,precision:2  ">面层厚度最大值</th>
                <th data-options="field:'FORMULACOEFF1',editor:'numberbox',width:80,align:'center' ,min:0,precision:2,formatter:_css.formatNumber">公式系数1</th>
                <th data-options="field:'FORMULACOEFF2',editor:'numberbox',width:80,align:'center' ,min:0,precision:2,formatter:_css.formatNumber">公式系数2</th>
                <th data-options="field:'FORMULACOEFF3',editor:'numberbox',width:80,align:'center' ,min:0,precision:2,formatter:_css.formatNumber">公式系数3</th>
                <th data-options="field:'FORMULACOEFF4',editor:'numberbox',width:80,align:'center' ,min:0,precision:2,formatter:_css.formatNumber">公式系数4</th>
                <th data-options="field:'FORMULACOEFF5',editor:'numberbox',width:80,align:'center' ,min:0,precision:2,formatter:_css.formatNumber">公式系数5</th>
                <th data-options="field:'COEFF',editor:'numberbox',width:80,align:'center' ,min:0,precision:2,formatter:_css.formatNumber">相关系数</th>
                <th data-options="field:'CALIBRATED',editor:'datebox',width:80,align:'center' ,formatter:_css.formatDate">校定时间</th>
                <th data-options="field:'REGBEGIN',editor:'text',width:80,align:'center'">回归起始年</th>
                <th data-options="field:'REGEND',editor:'text',width:80,align:'center'">回归结束年</th>
                <th data-options="field:'LASTYEAR',editor:'text',width:80,align:'center',hidden:true">模型数据年份</th>
                <th data-options="field:'PERFYEAR',editor:'text',width:80,align:'center' ">最新数据年份</th>
			</tr>
        </thead>
    </table>
   
    <div id="tb">
        <a id="btnShow" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" >查看模型</a>
        <a id="btnGraph" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" >查看图形</a>
        <select id="cmbIndex" class="easyui-combobox" style="width:100px" data-options="prompt:'指标类型',valueField:'id',textField:'text',panelHeight:'auto'">
        </select>   
        <select id="cmbPvmt" class="easyui-combobox" style="width:100px" data-options="prompt:'面层类型',valueField:'id',textField:'text',panelHeight:'auto'">
        </select>  
         <select id="cmbBasic" class="easyui-combobox" style="width:100px" data-options="prompt:'路面类型',valueField:'id',textField:'text',panelHeight:'auto'">
        </select>  
        <select id="cmbModel" class="easyui-combobox" style="width:100px" data-options="prompt:'模型形式',valueField:'id',textField:'text',panelHeight:'auto'">
        </select>    
         <select id="cmbType" class="easyui-combobox" style="width:100px" data-options="prompt:'养护类型',valueField:'id',textField:'text',panelHeight:'auto'">
        </select>  
        <label><input id="chkCheck" name="chkCheck" type="checkbox" />有新数据的模型</label> 
    </div>

    <div id="dlg" class="easyui-dialog" title="查看模型信息" style="width:450px;height:200px;padding:10px" data-options="
                closed:true,
				iconCls: 'icon-save',
				buttons: '#dlg-buttons'">
        <form id="fm" class="easyui-form">
            <table>			     
                <tr style="display:none">
                    <td>模型Id:</td>
                    <td><input name='Modelgroup_Id' class='easyui-textbox'  data-options="readonly:true" />
                    </td>
                </tr>
                <tr>
                    <td>模型组:</td>
                    <td><input id='ModelName' name='ModelName' class='easyui-textbox'  style="width:300px" data-options="readonly:true" /></td>
                </tr>
                <tr>
                    <td>数据年份:</td>
                    <td><input id='BeginYear' name='BeginYear' class='easyui-numberbox'  style="width:100px"   data-options="readonly:true" />&nbsp;年~
                        <input id='EndYear'  name='EndYear' class='easyui-numberbox' style="width:100px"   data-options="readonly:true" />&nbsp;年</td>
                </tr>

                <tr>
                    <td>PCI数据点数:</td>
                    <td><input id='PciCount' name='PciCount' class='easyui-numberbox' style="width:100px"   data-options="readonly:true" />&nbsp;个</td>
                </tr>
		    </table>
        </form>
    </div>

    <!--编辑数据命令-->
    <div id="dlg-buttons">
		<a id="btnSave" href="javascript:void(0)" class="easyui-linkbutton" >校正模型</a>
		<a id="btnCancel" href="javascript:void(0)" class="easyui-linkbutton" >取消查看</a>
	</div>

    <div id="dlg1" class="easyui-dialog" title="模型校正" style="width:450px;height:200px;padding:10px" data-options="
                closed:true,
				iconCls: 'icon-save',
				buttons: '#dlg-buttons1'">
        <form id="fm1" class="easyui-form">
            <table>			
                <tr>
                    <td>模型组:</td>
                    <td><input id='ModelName1' class='easyui-textbox'  style="width:300px" data-options="readonly:true" /></td>
                </tr>
                 <tr>
                    <td>模型形式:</td>
                    <td>
                        <select id="cmbModelMode" class="easyui-combobox" style="width:100px" data-options="prompt:'模型形式',valueField:'id',textField:'text',panelHeight:'auto'">
                        </select>   
                    </td>
                </tr>
                <tr>
                    <td>回归年份:</td>
                    <td><select id="cmbBeginYear" class="easyui-combobox" style="width:100px" data-options="prompt:'开始年',valueField:'id',textField:'text',panelHeight:'auto'">
                        </select> &nbsp;年~ 
                        <select id="cmbEndYear" class="easyui-combobox" style="width:100px" data-options="prompt:'结束年',valueField:'id',textField:'text',panelHeight:'auto'">
                        </select> &nbsp;年</td>
                </tr>
		    </table>
        </form>
    </div>

    <div id="dlg-buttons1">
		<a id="btnAdjust" href="javascript:void(0)" class="easyui-linkbutton" >开始校正</a>
	</div>

    <div id="dlg2" class="easyui-dialog" title="查看模型图形" style="width:800px;height:600px;overflow:auto;padding:10px;" data-options="closed:true,iconCls:'icon-ok'">
        <div id="container" style="width:720px;height:500px;"  />
	</div>
</asp:Content>
